<?php
header('Content-Type: text/html; charset=UTF-8');
include("connect.php");
$result = pg_query($dbConn, "SELECT id, titulo, aviso, id_rubro, estado FROM avisos WHERE id=".$_REQUEST["id"]);
if ($row = pg_fetch_object($result)) {
	$tituloAviso = $row->titulo;
	$textoAviso = $row->aviso;
	$estadoAviso = $row->estado;
	$rubroAviso = $row->id_rubro;
	$id = $row->id;
}
?>

<script
	type="text/javascript" src="scripts/jquery.min.js"></script>
<script
	type="text/javascript" src="scripts/jquery.validate.js"></script>
<script
	type="text/javascript" src="scripts/ckeditor.js"></script>
<script type="text/javascript">
	$(document).ready(function () {
		$("#nombre").focus();
		$("#form").validate();
	});
</script>

<?php
include_once("cabecera.php");
?>
<div id="contenido">
	<div id="colIzquierda">
		<form id="formEditarAviso" method="post"
			action="guardarCambiosAviso.php">
			<div id="datosAviso">
				<span>Titulo del aviso: </span>
				<input id="titulo" class="required"	name="titulo" value="<?php echo $tituloAviso;?>"></input> 
				<span>Estado actual: </span> 
				<select name="estado"
					id="estado">
					<option value='<?php echo $estadoAviso;?>'>
						<?php echo $estadoAviso;?>
					</option>
					<option value='Activo'>Activo</option>
					<option value='Inactivo'>Inactivo</option>
				</select> 
				<span>Rubro Actual: </span> 
				<select name="rubro" id="rubro">
					<option value='<?php echo $rubroAviso;?>'>
						<?php echo $rubroAviso;?>
					</option>
					<?php  
					include("connect.php");
					$result = pg_query($dbConn, "SELECT id, nombre FROM rubros");
					while ($row = pg_fetch_object($result)) {
									echo "<option value='$row->id'>$row->nombre</option>";
								}
								?>
				</select>
			</div>
			<textarea id="aviso" class="required ckeditor" name="aviso"
				type="text" rows="10" cols="30">
				<?php echo $textoAviso;?>
			</textarea>
			<input id="id" name="id" type="hidden" value="<?php echo $id;?>"></input>
			<input type="submit"></input>
		</form>
	</div>
</div>
<?php
include_once("pie.php");
?>
